<?php
/* 截取一定长度的完整的中文字符 */

/** 
***@Author:LAD 
***@URL :<a href="http://www.cnpik.com/" target="_blank">http://www.cnpik.com/</a> 
***@E_mail:lianxiwoo@sohu.com 
***@随便用，不收钱 :-) 
*/ 

function cnsubstr($string,$sublen=10,$filling="···") 
{ 
if($sublen>=strlen($string)) 
{ 
return $string; 
} 
$s=""; 
for($i=0;$i<$sublen;$i++) 
{ 
if(ord($string{$i})>127) 
{ 
$s.=$string{$i}.$string{++$i}; 
continue; 
}else{ 
$s.=$string{$i}; 
continue; 
} 
} 
//$s = str_replace('不要','-',$s);
return $s.$filling; 
}// End Function cnSubStr($string,$sublen) 

function clearHtml($content) {  
   $content = preg_replace("/&nbsp;/i", "", $content);
   $content = preg_replace("/<a[^>]*>/i", "", $content);
   $content = preg_replace("/<\/a>/i", "", $content);
   $content = preg_replace("/<p[^>]*>/i", "", $content);  
   $content = preg_replace("/<\/p>/i", "", $content);
   $content = preg_replace("/<div[^>]*>/i", "", $content);  
   $content = preg_replace("/<\/div>/i", "", $content);
   $content = preg_replace("/<!--[^>]*-->/i", "", $content);//注释内容  
   $content = preg_replace("/style=.+?['|\"]/i",'',$content);//去除样式  
   $content = preg_replace("/class=.+?['|\"]/i",'',$content);//去除样式  
   $content = preg_replace("/id=.+?['|\"]/i",'',$content);//去除样式     
   $content = preg_replace("/lang=.+?['|\"]/i",'',$content);//去除样式      
   $content = preg_replace("/width=.+?['|\"]/i",'',$content);//去除样式   
   $content = preg_replace("/height=.+?['|\"]/i",'',$content);//去除样式   
   $content = preg_replace("/border=.+?['|\"]/i",'',$content);//去除样式   
   $content = preg_replace("/face=.+?['|\"]/i",'',$content);//去除样式   
   $content = preg_replace("/face=.+?['|\"]/",'',$content);//去除样式 只允许小写 正则匹配没有带 i 参数
   return $content; 
} 


function getMenuname($databasepre,$val){
	$sql="select field1 from ".$databasepre."general ";
	if(!empty($val)){
		$sql .=" where id='".$val."'";
	}
	//echo $sql;
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row['field1'];
}

function getFirstpic($databasepre,$val){
	$sql="select fpath from ".$databasepre."file ";
	if(!empty($val)){
		$sql .=" where parentid='".$val."' order by createdate asc,seq asc";
	}
	//echo $sql;
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row['fpath'];
}
/* 执行一个sql返回一个字符串 */
function getProductNumSQL($id,$databasepre) {
	$sql="select count(*) as COUNTNUM from ".$databasepre."product ";
	if(!empty($id)){
		$sql .=" where PARENTID=".$id;
	}
	//echo $sql;
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row['COUNTNUM'];

}


/* 执行一个sql返回一个字符串 */
function getOneFiledbySQL($sql) {
	//echo $sql;
	if(empty($sql)){
		return "";
	}
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row['filedname'];

}
?>